<template>
  <div>
    <div>
      <el-form :inline="true" :model="formInline" class="demo-form-inline">
        <el-form-item label="核心企业名称">
          <el-input v-model="formInline.businessName" placeholder="核心企业名称"></el-input>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" icon="el-icon-search" @click="searchCreditUsed">查询</el-button>
        </el-form-item>
      </el-form>
    </div>
    <div>
      <el-table :data="tableData" border style="width: 100%">
        <el-table-column
          prop="enterpriseCredit.coreEnterprise.business_name"
          label="核心企业名称"
          width="150"
        ></el-table-column>
        <el-table-column prop="enterpriseCredit.loanProductName" label="授信产品名称" width="150"></el-table-column>
        <el-table-column prop="enterpriseCredit.creditLine" label="授信额度" width="150"></el-table-column>
        <el-table-column prop="creditUsedAmount" label="用信金额" width="150"></el-table-column>
        <el-table-column prop="creditBalance" label="用信余额" width="150"></el-table-column>
        <el-table-column prop="creditUsedDescription" label="用途" width="120"></el-table-column>
        <el-table-column prop="updateTime" label="操作时间" width="120"></el-table-column>
        <el-table-column label="操作" width="120">
          <template slot-scope="scope">
            <el-button
              size="mini"
              type="danger"
              icon="el-icon-delete"
              @click="handleDelete(scope.$index, scope.row)"
            >删除</el-button>
          </template>
        </el-table-column>
      </el-table>
    </div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      tableData: [],
      formInline: {
        businessName: ""
      },
      packagedialogFormVisible: false,
      moneydialogFormVisible: false,
      form: {
        enterpriseCredit: {
          id:""
        },
        packageName: "",
        carType: "",
        totalHour: "",
        trainModel: "",
        payModel: "",
        effectDate: "",
        ineffectDate: "",
        trainCost: "",
        platformCost: "",
        certificateCost: "",
        testfirstCost: "",
        testsecondCost: "",
        testthirdCost: "",
        testfourthCost: "",
        totalPrice: ""
      },
      formLabelWidth: "100px",
      title: "",
      moneyData: []
    };
  },
  created() {
    this.getAllCreditUsed();
  },
  methods: {
    addCreditUsed() {
      this.title = "添加";
      this.packagedialogFormVisible = true;
    },
    modifyDriverPackage() {
      if (this.title == "添加") {
        this.$axios
          .post("http://localhost:8080/appoint", this.form)
          .then(resp => {
            console.log("添加成功");
            this.getAppoints();
          });
      } else if (this.title == "修改") {
        this.$axios
          .put("http://localhost:8080/appoint", this.form)
          .then(resp => {
            console.log("修改成功");
            this.getAppoints();
          });
      }
    },
    getAllCreditUsed() {
      this.$axios.get("http://localhost:8800/creditUsed/all").then(resp => {
        console.log(resp);
        this.tableData = resp.data.data;
      });
    },
    getCreditUsed() {
      console.log(this.formInline);
      this.$axios
        .get(
          "http://localhost:8800/creditUsed/businessName/" +
            this.formInline.businessName
        )
        .then(resp => {
          console.log(resp);
          this.tableData = resp.data.data;
        });
    },
    searchCreditUsed() {
      this.getCreditUsed();
    },
    handleEdit(index, row) {
      this.form = { ...row };
      this.title = "修改";
      this.packagedialogFormVisible = true;
    },
    handleDelete(index, row) {
      this.$confirm("此操作将永久删除该条目, 是否继续?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      })
        .then(() => {
          this.$axios
            .delete("http://localhost:8080/driverPackage/" + row.packageId)
            .then(resp => {
              console.log("删除成功");
              this.getAppoints();
            });
          this.$message({
            type: "success",
            message: "删除成功!"
          });
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消删除"
          });
        });
    },
    modifyok() {
      this.modifyDriverPackage();
      this.packagedialogFormVisible = false;
    },
    closeDialog() {
      this.form = {};
      this.packagedialogFormVisible = false;
      this.moneydialogFormVisible = false;
    },
    readDetail(index, row) {
      this.moneydialogFormVisible = true;
      this.moneyData = [
        { costprogram: "培训费用", costMoney: row.trainCost },
        { costprogram: "平台费用", costMoney: row.platformCost },
        { costprogram: "制证费用", costMoney: row.certificateCost },
        { costprogram: "科一考试费", costMoney: row.testfirstCost },
        { costprogram: "科二考试费", costMoney: row.testsecondCost },
        { costprogram: "科三考试费", costMoney: row.testthirdCost },
        { costprogram: "科四考试费", costMoney: row.testfourthCost }
      ];
    }
  }
};
</script>

<style>
</style>